<template>
	<view>
		<view class="section">
			<view class="section-1 flex-align">
				<view class="image">
					<image :src="data.cover"></image>
				</view>
				<view class="detail">
					<view>
						<view class="detail-1">
							{{ data.name }}
						</view>

						<view class=""
							style="display: flex; flex-direction: row; align-items: center;margin-top: 20rpx;">
							<view class=" flex-align"
								style="font-size: 22rpx;color: #2F75FA;background-color: #d5e3fe;border-radius: 8rpx;padding: 5rpx 10rpx;margin-right: 20rpx;">
								游泳体验课
							</view>
							<image style="width: 25rpx;height: 25rpx;"
								src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/f1c02d6507d5b869a8fa25b144993dc02a42e038.png"
								mode=""></image>
							<view style="color: #FE8C61;font-size: 24rpx;margin-left: 6rpx;">
								招生中
							</view>
						</view>

						<view style="font-size: 24rpx;color: #4E6EAF;margin-top: 20rpx;">
							三香路体育馆
						</view>

						<!-- <view class="flex-align" style="margin-top: 30rpx">
							<view v-for="(item, index) in checkedSpec" :key="index" style="margin-right: 10rpx">
								<u-tag :text="item.name"></u-tag>
							</view>
						</view> -->
					</view>
					<view style=" display: flex; align-items: center;justify-content: space-between;">
						<view style="font-size: 24rpx;color: #4E6EAF;margin-top: 20rpx;">
							10课时
						</view>
						<view class="btns_ms">
							<view class="btns_m" @click="schedule" v-if="look">
								查看课表
							</view>
						</view>
					</view>

					<view style=" display: flex; align-items: center;justify-content: space-between;">
						<view class="price">￥<text>100</text>
						</view>
						<view class="detail-2">剩余名额:<text style="color: orange">25</text></view>
					</view>
				</view>
			</view>

			
			<view>
				<view class="section-2" v-for="(im, ix) in productlist" :key="ix">
					<view class="sub-title">{{ im.specificationsName }}</view>
					<view class="tag-list">
						<view v-for="(item2, index2) in im.specValueList" :key="index2" @click="selectSpec(im, item2)"
							style="display: flex;flex-direction: column; ;align-items: center;  justify-content: center; flex-wrap: wrap;">
							<!-- <img :src="item2.img" style="width: 50rpx; height: 50rpx;" /> -->
							<view v-if="item2.img" :class="[
							  item2.selected ? 'menu-image' : 'menu-image-no-checked',
							]">
								<image style="border-radius: 50% 50%;" :src="item2.img" mode="scaleToFill" />
							</view>
							<!-- <view class="menu-image-no-checked" v-else>
			
							</view> -->
							<view class="spec-value" :class="item2.selected ? 'text_color' : ''">
								{{ item2.specificationsValue }}
							</view>
						</view>
					</view>
				</view>
				<view class="btns" @click="handSubmit">立即购买</view>
			</view>
			
			
			<view class="" style="width: 100%;height: 140rpx;"></view>
			<view class=""
				style="width: 100%;height: 140rpx;background-color: rgb(255, 255, 255);position: fixed;bottom: 0;left: 0;">
				<view class="" style="display: flex;flex-direction: row;justify-content: space-between; ">
					<view class=""
						style="display: flex;flex-direction: column;justify-content: center;width: 20%;  align-items: center; ">
						<image style="width: 35rpx;height: 35rpx;"
							src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/d5ecd2223cffd867d1acd21f321df95a17ff71bc.png"
							mode=""></image>
						<view class="" style="font-size: 24rpx;color: #333333;margin-top: 10rpx;">
							分享
						</view>
					</view>
					<view class="" style="display: flex;flex: 1;">
						<view class="btns" @click="handSubmit" v-if="stock > 0">立即报名</view>
						<view class="btns_s" @click="handSubmit" v-if="stock == 0">立即报名</view>
					</view>
				</view>
			</view>
			<con-alert :show="alertShow" @close="close" :title="full_name">
				<view class="select-list">
					<view class="item flex-align" v-for="(item,index) in courseData" :key="index">
						<view class="detail">
							<view class="flex-between bottom">
								<view class="flex-align" style="width: 10%">
									<text class="address">{{index}}</text>
								</view>
								<view class="flex-align" style="width: 20%">
									<text>{{item.course_name}}</text>
								</view>
								<view class="flex-align" style="width: 20%">
									<text>{{item.course_date}}</text>
								</view>
								<view class="flex-align" style="width: 10%">
									<text>{{item.name}}</text>
								</view>
								<view class="flex-align" style="width: 20%">
									<text>{{item.period_time}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</con-alert>
		</view>
	</view>
</template>

<script>
	const train = require("@/api/train/index.js");
	import conAlert from "@/components/com-alert/com-alert.vue";
	export default {
		components: {
			conAlert
		},
		data() {
			return {
				productlist: [{
						specificationsName: "型号",
						specValueList: [{
								specificationsValue: "深洁牙线",
								id: '1',
								selected: true 
							},
							{
								specificationsValue: "深洁牙线1",
								id: '2',
								selected: false
							}
						]
					},
					{
						specificationsName: "SKU",
						specValueList: [{
								specificationsValue: "微蜡牙线，50米*1盒",
								id: '11',
								img: 'https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/77/1924b34af8264ccbb076655af84961.png?attname=e9d4f6691658f09033904a28a4da78cd.png',
								selected: true 
							},
							{
								specificationsValue: "舒适牙线，40米*1盒",
								id: '12',
								img: 'https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/77/1924b34af8264ccbb076655af84961.png?attname=e9d4f6691658f09033904a28a4da78cd.png',
								selected: false
							},
							{
								specificationsValue: "劲爽牙线，30米*1盒",
								id: '13',
								img: 'https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/77/1924b34af8264ccbb076655af84961.png?attname=e9d4f6691658f09033904a28a4da78cd.png',
								selected: false
							}
						]
					}
				],
				selectedIds: []
			};
		},

		onLoad(options) {

		},

		methods: {
			selectSpec(group, item) {
				group.specValueList.forEach((v) => {
					v.selected = false;
				});
				item.selected = true;
			
				
			},
			handSubmit() {
				// 查找选中的规格项
				let selectedSpecs = [];
				this.productlist.forEach((group) => {
					group.specValueList.forEach((item) => {
						if (item.selected) {
							selectedSpecs.push({
								specificationsName: group.specificationsName,
								specificationsValue: item.specificationsValue,
								img: item.img
							});
						}
					});
				});
				// 更新选中的规格值的id数组
				this.selectedIds = this.productlist.flatMap(im =>
					im.specValueList.filter(v => v.selected).map(v => v.id)
				);
				// 输出选中的规格项信息（在实际项目中可能会进一步处理）
				console.log("选中的规格项：", selectedSpecs);
				console.log(this.selectedIds, 'this.selectedIds')
			},
			handSubmit() {
				uni.navigateTo({
					url: "./train_student?id=" +
						this.data.id + "&stock=" +
						this.stock + "&price_selling=" +
						this.price_selling +
						"&venue_name=" +
						this.venue_name +
						"&train_enum_id=" +
						this.train_enum_id +
						"&sku=" +
						this.goods_sku +
						"&skucode=" +
						this.goods_code + "&venue_id=" +
						this.venue_id + "&sku_id=" +
						this.sku_id,
				});


			},

		},
	};
</script>

<style lang="scss" scoped>
	.tag-list {
		display: flex;
		flex-wrap: wrap;
	}
	
	.spec-value {
		padding: 5rpx 10rpx;
		margin: 5px;
		cursor: pointer;
		border: #fff 1rpx solid;
	}
	
	.text_color {
		color: #3498db;
		border: 1rpx solid #3498db;
	}
	
	.btns {
		cursor: pointer;
		padding: 10px;
		margin-top: 20px;
		text-align: center;
		background-color: #3498db;
		color: #fff;
	}
	
	.menu-image {
		width: 100rpx;
		height: 100rpx;
		background: url('https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/60cb40ff572199778113a809978ef6aa0f09db36.png') 100% no-repeat;
		background-size: 100% 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	
		image {
			width: 60rpx;
			height: 60rpx;
		}
	}
	
	.menu-image-no-checked {
		width: 100rpx;
		height: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	
		image {
			width: 60rpx;
			height: 60rpx;
		}
	}
	
	
	.section {
		padding: 24rpx;

		.select-list {
			.item {
				margin-bottom: 20rpx;
				padding-bottom: 20rpx;
				height: 50rpx;
				border-bottom: 1px solid #cccccc;
				padding: 0;

				&:last-of-type {
					border: none;
					margin: 0;
					padding: 0;
				}

				.image {
					width: 150rpx;
					height: 100%;

					/deep/ .vue-ref {
						width: 100%;
						height: 100%;
					}
				}

				.detail {
					display: flex;
					height: 100%;
					flex: 1;
					width: 0;
					margin-left: 20rpx;
					flex-direction: column;
					justify-content: space-between;

					.name {
						font-weight: 700;
						font-size: 28rpx;
						margin-bottom: 15rpx;
					}

					.timer {
						color: #cacaca;
						font-size: 20rpx;
					}

					.bottom {
						font-size: 20rpx;
						color: #101010;

						.address {
							width: 70%;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
						}
					}
				}
			}
		}

		.btns {
			background: linear-gradient(0deg, #528EFF, #2F75FA);
			border-radius: 20px;
			font-size: 28rpx;
			font-weight: bold;
			color: #FFFFFF;
			// padding: 26rpx 0;
			// margin: 0px 30rpx;
			// margin-top: 120rpx;
			text-align: center;
			// position: fixed;
			// bottom: 24px;
			// right: 5%;
			width: 90%;
			height: 80rpx;
			line-height: 80rpx;
		}

		.btns_m {
			background: linear-gradient(0deg, #528EFF, #2F75FA);
			border-radius: 5px;
			font-size: 28rpx;
			font-weight: bold;
			color: #FFFFFF;
			padding: 26rpx 0;
			width: 160rpx;
			height: 60rpx;
			text-align: center;
			line-height: 12rpx;

		}

		.btns_ms {
			// position: absolute;
			// right: 10rpx;
			// top: 110rpx;
		}

		.btns_s {
			background: linear-gradient(0deg, #bebebe, #bebebe);
			border-radius: 20px;
			font-size: 28rpx;
			font-weight: bold;
			color: #FFFFFF;
			// padding: 26rpx 0;
			// margin: 0px 30rpx;
			// margin-top: 120rpx;
			text-align: center;
			// position: fixed;
			// bottom: 24px;
			// right: 5%;
			width: 90%;
			height: 80rpx;
			line-height: 80rpx;
		}

		.section-1 {
			height: 250rpx;



			.image {
				width: 200rpx;
				height: 250rpx;
				margin-right: 26rpx;
				border-radius: 10rpx;
				overflow: hidden;

				image {
					width: 100%;
					height: 250rpx;
				}
			}

			.detail {
				flex: 1;
				width: 0;
				display: flex;
				height: 100%;
				flex-direction: column;
				justify-content: space-between;

				.detail-1 {
					font-size: 27rpx;
					font-weight: 500;
					color: #333333;
				}

				.detail-2 {
					font-size: 24rpx;
					font-weight: 500;
					color: #888888;
					margin-top: 12rpx;
				}

				.price {
					font-size: 20rpx;
					font-weight: 500;
					color: #ff0000;

					text {
						font-size: 32rpx;
						font-weight: 700;
					}
				}
			}
		}

		.section-2 {
			margin-top: 30rpx;

			.top-menu-list {
				display: flex;
				flex-wrap: wrap;

				.top-menu-item {
					display: flex;
					flex-direction: column;
					align-items: center;
					width: 20%;
					// margin-top: 10rpx;
					padding: 0px 30rpx;
					box-sizing: border-box;
					font-size: 25rpx;

					.add_na {
						display: flex;
						flex-direction: column;
						align-items: center;
						width: 20%;
						// margin-top: 30rpx;
						padding: 0px 30rpx;
						box-sizing: border-box;
						font-size: 25rpx;

						.menu-image {
							width: 100rpx;
							height: 100rpx;
							// border-radius: 37rpx;
							// background: rgb(250, 237, 234);
							// background: linear-gradient(45deg,
							// 		rgba(250, 237, 234, 1) 0%,
							// 		rgba(246, 227, 216, 1) 77%);
							background: url('https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/60cb40ff572199778113a809978ef6aa0f09db36.png') 100% no-repeat;
							background-size: 100% 100%;
							// position: absolute;
							// top: 0;
							// right: 0;
							// z-index: 999;
							display: flex;
							justify-content: center;
							align-items: center;

							image {
								width: 60rpx;
								height: 60rpx;
							}
						}

						.menu-image-no-checked {
							width: 100rpx;
							height: 100rpx;
							display: flex;
							justify-content: center;
							align-items: center;

							image {
								width: 60rpx;
								height: 60rpx;
							}
						}

						.no-checked-text {
							white-space: nowrap;
						}

						.checked-text {
							margin-top: 20rpx;
							white-space: nowrap;
							font-weight: bold;
						}
					}
				}
			}

			.sub-title {
				font-size: 28rpx;
				font-weight: bold;
				color: #333333;
				margin-bottom: 20rpx;
			}

			.tag-list {
				display: flex;
				flex-wrap: wrap;

				/deep/.u-tag {
					margin-left: 30rpx;
					margin-bottom: 30rpx;
				}

				// .tag{
				// 	background: #EFEFEF;
				// 	border-radius: 3px;
				// 	font-size: 24rpx;
				// 	font-weight: 500;
				// 	color: #FFFFFF;
				// 	padding: 7rpx 20rpx;
				// 	margin-right: 20rpx;
				// 	margin-bottom: 20rpx;
				// }

			}
		}



		.section-3 {
			font-size: 22rpx;
			font-weight: 500;
			color: #333333;
		}
	}
</style>